package com.gzsxy.NIO.netty.inboundhandlerandoutboundhandler;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @author xiaolong
 * @version 1.0
 * @description: 如果传入的值的类型不跟定义的类型一致，就跳过encode
 * @date 2022/5/17 21:36
 */
public class MyLongToByteEncoder extends MessageToByteEncoder<Long> {

    //编码方法
    @Override
    protected void encode(ChannelHandlerContext ctx, Long msg, ByteBuf out) throws Exception {

        System.out.println("MyLongToByteEncoder encode 被调用");
        System.out.println("msg=" + msg);
        out.writeLong(msg);

    }

}
